import { defineStore } from 'pinia'

const useOption = defineStore('useOption', {
  state: () => ({
    asideWidth: localStorage.getItem('asideWidth')
      ? Number(localStorage.getItem('asideWidth'))
      : 220,
    theme: (localStorage.getItem('theme') as 'theme-light' | 'theme-dark') || 'theme-light',
    // 导航栏菜单
    menuList: [
      {
        id: 1,
        title: '星际日志',
        path: '/home',
        icon: 'icon-shouye'
      },
      {
        id: 2,
        title: '星际日常',
        path: '/share',
        icon: 'icon-fenxiang'
      },
      {
        id: 3,
        title: '星际成果',
        path: '/product',
        icon: 'icon-xiangmu'
      },
      {
        id: 4,
        title: '星际维修站',
        path: '/upkeep',
        icon: 'icon-guanyuguwen'
      }
    ]
  }),
  actions: {
    // 设置主题
    saveTheme(val: 'theme-light' | 'theme-dark') {
      this.theme = val
      localStorage.setItem('theme', this.theme)
    },
    // 修改侧边栏宽度
    saveAsideWidth() {
      this.asideWidth = this.asideWidth === 220 ? 50 : 220
    }
  }
})

export default useOption
